<template>
  <div>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="tutor_id" label="ID" width="100"> </el-table-column>
      <el-table-column prop="tutor_name" label="教师用户名" width="120">
      </el-table-column>
      <el-table-column prop="tutor_pwd" label="用户密码" width="120">
      </el-table-column>
      <el-table-column prop="tutor_gender" label="教师性别" width="120">
      </el-table-column>
      <el-table-column prop="tutor_age" label="教师年龄" width="120">
      </el-table-column>
      <el-table-column prop="tutor_rank" label="教师职称" width="120">
      </el-table-column>
      <el-table-column prop="tutor_phone" label="教师手机号" width="120">
      </el-table-column>
      <el-table-column prop="tutor_avatar" label="教师头像" width="100">
      </el-table-column>
      <el-table-column prop="tutor_describes" label="教师介绍" width="350">
      </el-table-column>
      <el-table-column label="操作" width="250">
        <template slot-scope="scope">
          <el-button
            @click.native.prevent="deleteRow(scope.$index, tableData)"
            type="text"
            size="small"
          >
            移除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import Update from '@/components/Update.vue';
export default {
  components: { Update },
  data() {
    return {
      tableData: [],
    };
  },
  methods: {
    //删除操作
    deleteRow(index, rows) {
      console.log(rows[index].tutor_id); //获取当前项tutor_id
      
      let id = rows[index].tutor_id;
      console.log(id)
      let url = `http://localhost:8080/user/deleteTeacher?tutor_id=${id}`;
      this.axios.delete(url).then((res) => {
        console.log(res);
      });
      rows.splice(index, 1);
    },
    //向后端请求数据
    getData() {
      //  console.log(this)
      let url = "http://localhost:8080/user/selectTeacher";
      this.axios.get(url).then((res) => {
        console.log(res.data.result);
        this.tableData = res.data.result;
      });
    },
  },
  // 页面加载请求数据
  mounted() {
    this.getData();
  },
};
</script>

<style lang="scss" scoped></style>